﻿Public Class clsInhOferta
    Inherits clsOferta

#Region "Attributes"

    Private mvarPozycjeOferty As Collection(Of clsInhPozycjaOferty)
    Private mvarPozycjeOfertyDel As Collection(Of clsInhPozycjaOferty)

    Private mvarKlient As clsKlient
    Private mvarSposobWysylkiOferty As clsSposobWysylkiOferty
    Private mvarPracownik As clsPracownik
    Private mvarStatusOferty_Id As clsStatusOferty
    Private mvarEmail As clsEmail
    Private mvarWysylkaOferty As clsWysylkaOferty

    Private mvarOfertaAdresEmail As Collection(Of clsOfertaAdresEmail)

#End Region

#Region "Properties"

    Public Property OfertaAdresEmail() As Collection(Of clsOfertaAdresEmail)
        Get
            Return mvarOfertaAdresEmail
        End Get
        Set(ByVal value As Collection(Of clsOfertaAdresEmail))
            mvarOfertaAdresEmail = value
        End Set
    End Property
    Public Property PozycjeOferty() As Collection(Of clsInhPozycjaOferty)
        Get
            Return mvarPozycjeOferty
        End Get
        Set(ByVal value As Collection(Of clsInhPozycjaOferty))
            mvarPozycjeOferty = value
        End Set
    End Property

    Public Property PozycjeOfertyDel() As Collection(Of clsInhPozycjaOferty)
        Get
            Return mvarPozycjeOfertyDel
        End Get
        Set(ByVal value As Collection(Of clsInhPozycjaOferty))
            mvarPozycjeOfertyDel = value
        End Set
    End Property

    Public Property Klient As clsKlient
        Get
            Return mvarKlient
        End Get
        Set(ByVal value As clsKlient)
            mvarKlient = value
        End Set
    End Property


    Public Property Pracownik As clsPracownik
        Get
            Return mvarPracownik
        End Get
        Set(ByVal value As clsPracownik)
            mvarPracownik = value
        End Set
    End Property

    Public Property StatusOferty_Id As clsStatusOferty
        Get
            Return mvarStatusOferty_Id
        End Get
        Set(ByVal value As clsStatusOferty)
            mvarStatusOferty_Id = value
        End Set
    End Property


    Public Property SposobWysylkiOferty As clsSposobWysylkiOferty
        Get
            Return mvarSposobWysylkiOferty
        End Get
        Set(ByVal value As clsSposobWysylkiOferty)
            mvarSposobWysylkiOferty = value
        End Set
    End Property

    Public Property Email As clsEmail
        Get
            Return mvarEmail
        End Get
        Set(ByVal value As clsEmail)
            mvarEmail = value
        End Set
    End Property

#End Region

#Region "Methods"

    Public Sub New()
        MyBase.New()
        mvarPozycjeOferty = New Collection(Of clsInhPozycjaOferty)
        mvarPozycjeOfertyDel = New Collection(Of clsInhPozycjaOferty)
    End Sub

    Public Sub New(ByVal ID As Integer, ByVal lvarDbHolder As clsDataBase)

        MyBase.New(ID, lvarDbHolder, VAR_ERROR_HANDLER)
        mvarPozycjeOferty = New Collection(Of clsInhPozycjaOferty)
        mvarPozycjeOfertyDel = New Collection(Of clsInhPozycjaOferty)

        mvarOfertaAdresEmail = New Collection(Of clsOfertaAdresEmail)

        mvarKlient = New clsKlient(MyBase.KlientID, lvarDbHolder, VAR_ERROR_HANDLER)
        mvarSposobWysylkiOferty = New clsSposobWysylkiOferty(MyBase.SposobWysylkiOfertyId, lvarDbHolder, VAR_ERROR_HANDLER)
        mvarEmail = New clsEmail(MyBase.EmailId, lvarDbHolder, VAR_ERROR_HANDLER)
        mvarStatusOferty_Id = New clsStatusOferty(MyBase.StatusOfertyId, lvarDbHolder, VAR_ERROR_HANDLER)
        mvarPracownik = New clsPracownik(MyBase.PracownikId.ToString(), lvarDbHolder, VAR_ERROR_HANDLER)

        Dim lvarTabel As DataTable = clsOferta.PobierzWszystkiePozycje(lvarDbHolder, VAR_ERROR_HANDLER, ID)

        If Not lvarTabel Is Nothing Then
            For Each lvarRow As DataRow In lvarTabel.Rows
                mvarPozycjeOferty.Add(New clsInhPozycjaOferty(CInt(lvarRow.Item("id")), lvarDbHolder))
            Next
        End If

    End Sub

    Public Overloads Sub Save(ByVal lvarDbHolder As clsDataBase)


        MyBase.Save(lvarDbHolder, VAR_ERROR_HANDLER)

        For Each lvarPozycja As clsInhPozycjaOferty In mvarPozycjeOfertyDel
            lvarPozycja.Delete(lvarDbHolder)
        Next

        For Each lvarPozycja As clsInhPozycjaOferty In mvarPozycjeOferty
            lvarPozycja.OfertaId = MyBase.ID
            lvarPozycja.Cena = Replace(lvarPozycja.Cena, ",", ".")
            lvarPozycja.Save(lvarDbHolder)
        Next

    End Sub

#End Region

End Class
